package ar.uba.tleng.g99.expregs.parser;

import java.util.Set;

import ar.uba.tleng.g99.expregs.automata.AutomataND;

public final class OrExpr implements Expr {

	private final Expr expr1;
	private final Expr expr2;

	public OrExpr(Expr expr1, Expr expr2) {
		this.expr1 = expr1;
		this.expr2 = expr2;
	}

	@Override
	public AutomataND automata(Set<Character> sigma) {
		return AutomataND.or(sigma, this.expr1.automata(sigma),
				this.expr2.automata(sigma));
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((expr1 == null) ? 0 : expr1.hashCode());
		result = prime * result + ((expr2 == null) ? 0 : expr2.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrExpr other = (OrExpr) obj;
		if (expr1 == null) {
			if (other.expr1 != null)
				return false;
		} else if (!expr1.equals(other.expr1))
			return false;
		if (expr2 == null) {
			if (other.expr2 != null)
				return false;
		} else if (!expr2.equals(other.expr2))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "OrExpr [expr1=" + expr1 + ", expr2=" + expr2 + "]";
	}

}
